#!/bin/bash

date_now=$(date "+%Y%m%d")

backUpFolder=/root/berrysup/bak/
username="root"
password="stpass"
db_name="berry_sup"

fileName="${db_name}_${date_now}.sql"

set -ex;
echo "starting backup mysql ${db_name} at ${date_now}."

#/usr/bin/mysqldump -u${username} -p${password} -h 192.168.90.72 --lock-all-tables --flush-logs ${db_name} > ${backUpFolder}${fileName}
/usr/bin/mysqldump --socket=/var/lib/mysql/mysql.sock -u $username -p${password} ${db_name} > ${backUpFolder}${fileName}

cd ${backUpFolder}
tar zcvf ${fileName}.tar.gz ${fileName}
rm -rf ${fileName}

date_end=$(date "+%Y%m%d-%H%M%S")

echo "finish backup mysql database ${db_name} at ${date_end}."
